VBcoders Browse New Submit Contact Sign In

No account? Register free

Forgot password?

Binary String<--> Numeric conversion THE RIGHT WAY {Updated}

Javin  (3 Submissions)   VB function enhancement   Visual Basic 3.0   Advanced   Wed 3rd February 2021

First some clarification: This takes a number (say, 65) and the number of bits you want returned (say 8) and returns a STRING of 1's and 0's (such as "01000001"). Also converts the other way, too. Since VB doesn't have any bitshifting capability, this MIGHT be the only way to do it. (If someone has a better method, by all means PLEASE let me know.)

I came in here looking for a quick and dirty method of doing this. I don't mean to be rude, people, but if you don't know what you're doing, don't upload the code. I poured through well over 2 dozen horribly ugly "methods" of conversion that all involved nested loops, select case, if/then trees, and all other sorts of nonsense. Finally, I gave up and wrote it myself. Once you understand the maths that go into making a binary number, you'll understand how simple this code really is. It can manage to convert any Long Integer to binary, and back again, quick, easy, and with a minimum of overhead. I'm sure there's probably even APIs to do this, now, but they likely wouldn't be available on legacy systems, and this method will work in any language. Note that this is marked as "Advanced" code. If you can't figure out how to use it, that's on you. In reality, it's pretty straightforward.

Rate Binary String<--> Numeric conversion THE RIGHT WAY {Updated} (11(11 Vote))
Binary String<--> Numeric conversion THE RIGHT WAY {Updated}.bas

Binary String<--> Numeric conversion THE RIGHT WAY {Updated} Comments

No comments yet — be the first to post one!

Post a Comment

0/1000 characters